package com.dayu.gulimall.product.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author dayu
 * @version 1.0
 * @email dayu007@foxmail.com
 * @date 2020/12/19 12:39
 * @description
 */
@Configuration
public class MyRedissionConfig {
    /**
     * 所有的redisson操作都是同故宫RedissonClient对象来完成
     * @return
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redissonClient() {
        // 默认连接地址 127.0.0.1:6379
        Config config = new Config();
        config.useSingleServer().setAddress("redis://192.168.1.161:6379");
        return Redisson.create(config);

        /**
         * 程序化配置主从模式的用法:
         *
         * Config config = new Config();
         * config.useMasterSlaveServers()
         *     //可以用"rediss://"来启用SSL连接
         *     .setMasterAddress("redis://127.0.0.1:6379")
         *     .addSlaveAddress("redis://127.0.0.1:6389", "redis://127.0.0.1:6332", "redis://127.0.0.1:6419")
         *     .addSlaveAddress("redis://127.0.0.1:6399");
         *
         * RedissonClient redisson = Redisson.create(config);
         */
    }
}
